package bootQuick.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;

public class DateUtils {
    public static Date StringToDate(SimpleDateFormat format, String dateStr) throws ParseException {
        return format.parse(dateStr);
    }

    public static String DateToString(SimpleDateFormat format, Date date) throws ParseException {
        return format.format(date);
    }

    public static LocalDateTime DateToLocalDateTime(Date date) {
        return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
    }

    public static Date LocalDateTimeToDate(LocalDateTime localDateTime) {
        ZoneId zoneId = ZoneId.systemDefault();
        ZonedDateTime zdt = localDateTime.atZone(zoneId);
        return Date.from(zdt.toInstant());
    }
}
